import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '../components/User/Login.vue';
import UserInfo from '../components/User/UserInfo.vue';
import Home from '../components/Home.vue';
import Comic from '../components/Comic/Comic.vue';
import HomePage from '../components/Comic/HomePage.vue';
import ComicNew from '../components/Comic/ComicNew.vue';
import HomePageNew from '../components/Comic/HomePageNew.vue';
import Test from '../components/Comic/test.vue';
import Enlarge from '../components/Comic/Enlarge.vue';
import IndexApp from '../components/App/IndexApp.vue';

Vue.use(VueRouter);

const routes = [
  { path: '/', redirect: '/appIndex' },
  { path: '/login', name: 'login', component: Login },
  { path: '/test', name: 'test', component: Test },
  { path: '/enlarge', name: 'enlarge', component: Enlarge },
  {
    path: '/home',
    name: 'home',
    component: Home,
    children: [
      { path: '/userInfo', name: 'userInfo', component: UserInfo }
    ]
  },
  {
    path: '/comic',
    name: 'comic',
    component: Comic,
    children: [
      { path: '/homePage', name: 'homePage', component: HomePage }
    ]
  },
  {
    path: '/comicNew',
    name: 'comicNew',
    component: ComicNew,
    children: [
      { path: '/homePageNew', name: 'homePageNew', component: HomePageNew }
    ]
  },
  { path: '/appIndex', name: 'appIndex', component: IndexApp }
];
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err);
};
const router = new VueRouter({
  routes
});

// router.beforeEach((to, from, next) => {
//   // console.log(Vue.$cookies);
//   const valib = Vue.$cookies.get('token');
//   if (to.path === '/login') return next();
//   if (valib == null) return next('/login');
//   if (!valib) return next('/login');
//   next();
// });
export default router;
